import { PSAjaxControlContainerImpl } from '../psajax-control-container-impl';
import { IPSDEForm } from './ipsdeform';
import { IPSDEFormItem } from './ipsdeform-item';
import { IPSDEFormItemUpdate } from './ipsdeform-item-update';
import { IPSDEFormItemVR } from './ipsdeform-item-vr';
import { IPSDEFormPage } from './ipsdeform-page';
import { IPSLayout } from '../layout/ipslayout';

export class PSDEFormImpl extends PSAjaxControlContainerImpl implements IPSDEForm {
  get codeName(): string {
    return this.M.codeName;
  }

  get defaultLabelWidth(): number {
    return this.M.defaultLabelWidth;
  }

  get formFuncMode(): 'WFACTION' | 'WIZARDFORM' {
    return this.M.formFuncMode;
  }

  get formStyle(): string {
    return this.M.formStyle;
  }

  get formWidth(): number {
    return this.M.formWidth != null ? this.M.formWidth : 0.0;
  }

  protected psdeformitemupdates: IPSDEFormItemUpdate[] | null = null;

  getPSDEFormItemUpdates(): IPSDEFormItemUpdate[] | null {
    if (this.psdeformitemupdates == null) {
      this.psdeformitemupdates = this.fillChildListModel(this.M.getPSDEFormItemUpdates, 'control.form.IPSDEFormItemUpdate') as IPSDEFormItemUpdate[];
    }
    return this.psdeformitemupdates;
  }

  get psDEFormItemUpdates(): IPSDEFormItemUpdate[] | null {
    return this.getPSDEFormItemUpdates();
  }

  findPSDEFormItemUpdate(objKey: any): IPSDEFormItemUpdate | null {
    return this.getPSModel5('control.form.IPSDEFormItemUpdate', this.getPSDEFormItemUpdates(), objKey) as IPSDEFormItemUpdate;
  }

  protected psdeformitemvrs: IPSDEFormItemVR[] | null = null;

  getPSDEFormItemVRs(): IPSDEFormItemVR[] | null {
    if (this.psdeformitemvrs == null) {
      this.psdeformitemvrs = this.fillChildListModel(this.M.getPSDEFormItemVRs, 'control.form.IPSDEFormItemVR') as IPSDEFormItemVR[];
    }
    return this.psdeformitemvrs;
  }

  get psDEFormItemVRs(): IPSDEFormItemVR[] | null {
    return this.getPSDEFormItemVRs();
  }

  findPSDEFormItemVR(objKey: any): IPSDEFormItemVR | null {
    return this.getPSModel5('control.form.IPSDEFormItemVR', this.getPSDEFormItemVRs(), objKey) as IPSDEFormItemVR;
  }

  protected psdeformitems: IPSDEFormItem[] | null = null;

  getPSDEFormItems(): IPSDEFormItem[] | null {
    if (this.psdeformitems == null) {
      this.psdeformitems = this.fillChildListModel(this.M.getPSDEFormItems, 'control.form.IPSDEFormItem') as IPSDEFormItem[];
    }
    return this.psdeformitems;
  }

  get psDEFormItems(): IPSDEFormItem[] | null {
    return this.getPSDEFormItems();
  }

  findPSDEFormItem(objKey: any): IPSDEFormItem | null {
    return this.getPSModel5('control.form.IPSDEFormItem', this.getPSDEFormItems(), objKey) as IPSDEFormItem;
  }

  protected psdeformpages: IPSDEFormPage[] | null = null;

  getPSDEFormPages(): IPSDEFormPage[] | null {
    if (this.psdeformpages == null) {
      this.psdeformpages = this.fillChildListModel(this.M.getPSDEFormPages, 'control.form.IPSDEFormPage') as IPSDEFormPage[];
    }
    return this.psdeformpages;
  }

  get psDEFormPages(): IPSDEFormPage[] | null {
    return this.getPSDEFormPages();
  }

  findPSDEFormPage(objKey: any): IPSDEFormPage | null {
    return this.getPSModel5('control.form.IPSDEFormPage', this.getPSDEFormPages(), objKey) as IPSDEFormPage;
  }

  protected pslayout: IPSLayout | null = null;

  getPSLayout(): IPSLayout | null {
    if (this.pslayout != null) return this.pslayout;
    const value = this.M.getPSLayout;
    if (value == null) {
      return null;
    }
    this.pslayout = this.getPSModel4('control.layout.IPSLayout', value, 'getPSLayout') as IPSLayout;
    return this.pslayout;
  }

  get psLayout(): IPSLayout | null {
    return this.getPSLayout();
  }

  getPSLayoutMust(): IPSLayout {
    const value = this.getPSLayout();
    if (value == null) {
      throw new Error('未指定表单布局对象');
    }
    return value;
  }

  get tabHeaderPos(): 'LEFT' | 'TOP' | 'RIGHT' | 'BOTTOM' {
    return this.M.tabHeaderPos;
  }

  get mobileControl(): boolean {
    return this.M.mobileControl != null ? this.M.mobileControl : false;
  }

  get noTabHeader(): boolean {
    return this.M.noTabHeader;
  }

  get cls(): string {
    return 'PSDEFormImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.form.IPSDEForm' || cls == 'control.layout.IPSLayoutContainer') return true;
    return super.instanceof(cls);
  }
}
